﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace DockSample.Line
{
    class EndLine:OriginalLine
    {
        public string complexLineId;
        public EndLine(Point point1, Point point2, OriginalDiagram endDiagram, string complexLineId)
            : base(point1, point2)
        {
            this.StartDiagram = new NullDiagram();
            this.EndDiagram = endDiagram;
            this.complexLineId = complexLineId;
            startDiagramSize = new Size(startDiagram.Width / 2, startDiagram.Height / 2);
            endDiagramSize = new Size(endDiagram.Width / 2, endDiagram.Height / 2);
        }

        public EndLine(Point point1, Point point2, string id, OriginalDiagram endDiagram, string complexLineId)
            : base(point1, point2, id)
        {
            this.StartDiagram = new NullDiagram();
            this.EndDiagram = endDiagram;
            this.complexLineId = complexLineId;
            startDiagramSize = new Size(startDiagram.Width / 2, startDiagram.Height / 2);
            endDiagramSize = new Size(endDiagram.Width / 2, endDiagram.Height / 2);
            
            
        }
        public override void Drawing(Graphics g, DummyModelForm m)
        {
            this.RefreshRelatedDiagram(this);
            Pen pen = new Pen(Color.Brown, 1);
            g.DrawLine(pen, GetStartShowPoint(), GetEndShowPoint());
            Point start = GetStartShowPoint();
            Point end = GetEndShowPoint();
            //画箭头
            double flRlt = Math.Sqrt((start.X - end.X) * (start.X - end.X) + (start.Y - end.Y) * (start.Y - end.Y));
            float flength = 10;//箭头长度
            if (flRlt == 0) return;
            double tmpX = end.X + (start.X - end.X) * flength / flRlt;
            double tmpY = end.Y + (start.Y - end.Y) * flength / flRlt;
            double fl1X = (tmpX - end.X) * Math.Sqrt((float)3) / 2 + (tmpY - end.Y) * 1 / 2 + end.X;
            double fl1Y = (tmpY - end.Y) * Math.Sqrt((float)3) / 2 - (tmpX - end.X) * 1 / 2 + end.Y;
            double fl2X = (tmpX - end.X) * Math.Sqrt((float)3) / 2 - (tmpY - end.Y) * 1 / 2 + end.X;
            double fl2Y = (tmpY - end.Y) * Math.Sqrt((float)3) / 2 + (tmpX - end.X) * 1 / 2 + end.Y;
            g.DrawLine(pen, new Point(end.X, end.Y), new Point((int)fl1X, (int)fl1Y));
            g.DrawLine(pen, new Point(end.X, end.Y), new Point((int)fl2X, (int)fl2Y));
        }
    }
}
